function xemchitiet(id) {
	$.ajax({url: '/demo/index.php/product/detail?id='+id, success: function(resp) {
		if($('#dialog').length == 0) {
			$('<div id="dialog"></div>').appendTo('body');
			$('<div id="dialog-wrapper"></div>').appendTo('body');
            $('#dialog-wrapper').click(function(){
                closeDialog();
            });
		}
		
		$('#dialog').html(resp);
		openDialog();
	}});
}

function openDialog() {
    $('#giohang').fadeIn();
	$('#dialog').fadeIn();
	$('#dialog-wrapper').fadeIn();
	$('#dialog-wrapper').width(window.screen.width);
	$('#dialog-wrapper').height(window.screen.height);
}

function closeDialog() {
	$('#dialog').fadeOut();
	$('#dialog-wrapper').fadeOut();
    $('#giohang').fadeOut(function(){
        $('#giohang').remove();
    });
}


function giohang() {
    $.ajax({url: '/demo/index.php/cart/show_cart', success: function(resp) {
        $('#dialog').remove();
        if($('#dialog-wrapper').length == 0) {
            $('<div id="dialog-wrapper"></div>').appendTo('body');
            $('#dialog-wrapper').click(function(){
                closeDialog();
            });
        }

        $('body').append(resp);
        openDialog();
    }});
}

$(document).ready(function() {
    $('.addcart').click(function(){
        $.ajax({
            type: "POST",
            url: "/demo/index.php/cart/add_cart",
            data: 'id='+$(this).attr('rel'),
			success: function() {
				closeDialog();
				giohang();
			}
        });
    });
});

function addToCart(id) {
	$.ajax({type: 'POST', url: '/demo/index.php/cart/add_cart', data: 'id='+id,success:function(){
		giohang();
	} });
}

$(function(){

setTimeout(function(){


  if($('#main_right_gioithieu').height() ){
        $('#main2').height($('#main_right_gioithieu').height()+70 );
    }
  else if($('#main_right_product').height()){
      $('#main2').height($('#main_right_product').height()+80 );
   } else {
	$('#main2').height(880);
   }
    }
);

}
)